﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsTest
{
    /// <summary>
    /// 聚集算法
    /// </summary>
    class GatherArithmetic
    {
        /// <summary>
        /// 两点间距离算法
        /// </summary>
        /// <param name="k">种子点坐标</param>
        /// <param name="p">目标点坐标</param>
        /// <returns>种子点与目标点的距离</returns>
        public static double GetLengthWithTwoPoint(int[] k,int[] p)
        {
            //利用三角函数定理（c^2=a^2+b^2）计算两点距离
            return Math.Sqrt((Math.Pow(Math.Abs(k[0]) - p[0], 2) + Math.Pow(Math.Abs(k[1] - p[1]), 2)));
        }

        /// <summary>
        /// 求数组中最小值方法
        /// </summary>
        /// <param name="ds">一元浮点数组</param>
        /// <returns>数组中的最小值</returns>
        public static double GetMin(double[] ds)
        {
            var min = ds[0];
            for (int i = 0; i < ds.Count(); i++)
            {
                if(min > ds[i])
                {
                    min = ds[i];
                }
            }
            return min;
        }

        /// <summary>
        /// 求数组中最大值方法
        /// </summary>
        /// <param name="ds">一元浮点数组</param>
        /// <returns>数组中的最大值</returns>
        public static double GetMax(double[] ds)
        {
            var max = ds[0];
            for (int i = 0; i < ds.Count(); i++)
            {
                if (max < ds[i])
                {
                    max = ds[i];
                }
            }
            return max;
        }
    }
}
